#!/usr/bin/env bash
set -euo pipefail

##? make install
##? make uninstall

export NAVI_HOME="$(cd "$(dirname "$0")/.." && pwd)"
source "${NAVI_HOME}/scripts/install"

install() {
   export SOURCE_DIR="${SOURCE_DIR:-"$(get_source_dir)"}"
   export BIN_DIR="${BIN_DIR:-"$(get_bin_dir)"}"
   echoerr "The final binary will be available at ${BIN_DIR}/navi..."
   "${NAVI_HOME}/scripts/action" release
   ln -s "${NAVI_HOME}/target/tar/navi" "${BIN_DIR}/navi"
}

uninstall() {
   export SOURCE_DIR="${SOURCE_DIR:-"$(get_source_dir)"}"
   rm -rf "${NAVI_HOME}/target"
   rm "$SOURCE_DIR"
}

cmd="$1"
shift

case "$cmd" in
   "install") install "$@" ;;
   "uninstall") uninstall "$@" ;;
esac
